package com.atguigu.eduservice.controller.front;

import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@RequestMapping("/eduservice/indexfront")
@CrossOrigin
public class IndexFrontController {

    @Autowired
    private EduCourseService courseService;//课程

    @Autowired
    private EduTeacherService teacherService;//讲师

    @GetMapping("index")
    public R index(){
        //查询前8条热门课程,查询前4条名师
        QueryWrapper<EduCourse> coursewrapper=new QueryWrapper<>();
        coursewrapper.orderByDesc("id");
        coursewrapper.last("limit 8");
        List<EduCourse> edulist = courseService.list(coursewrapper);

        //查询前四条名师
        QueryWrapper<EduTeacher> teacherwrapper=new QueryWrapper<>();
        teacherwrapper.orderByDesc("id");
        teacherwrapper.last("limit 4");
        List<EduTeacher> teacherlist = teacherService.list(teacherwrapper);
        return R.ok().data("edulist",edulist).data("teacherlist",teacherlist);
    }




}
